package game;

import java.util.ArrayList;
import java.util.Random;

public class Deck 
{
	private static ArrayList<Card> cards;
	private static ArrayList<Card> graveyard;
	
	public Deck()
	{
		cards = new ArrayList<Card>();
		
		for(int i = 0; i < 4; i++)
		{
			for(int j = 0; j < 13; j++)
			{
				cards.add(new Card(i,j));
			}
		}
		shuffleDeck();
	}
	
	private void shuffleDeck ()
	{
		Random rnd = new Random();
		for(int i = 0; i < cards.size(); i++)
		{
			int rndPlace = rnd.nextInt(cards.size() - 1);
			Card temp1 = cards.get(i);
			Card temp2 = cards.get(rndPlace);
			cards.set(i, temp2);
			cards.set(rndPlace, temp1);
		}
	}
	
	public Card drawFromDeck()
	{
		if(cards.isEmpty())
		{
			graveToDeck();
		}
		return cards.remove(0);
	}
	
	public int deckSize()
	{
		return cards.size();
	}
	
	private void graveToDeck()
	{
		for(int i = 0; i < graveyard.size(); i++)
		{
			cards.set(i, graveyard.get(i));
		}
		graveyard.clear();
		shuffleDeck();
	}
}
